import { defineConfig } from "vite";
import { fileURLToPath, URL } from "node:url";
import config from "./src/config/config";
import vue from "@vitejs/plugin-vue";
import ReactivityTransform from "@vue-macros/reactivity-transform/vite";

export default defineConfig({
  assetsInclude: ["**/*.shp"],
  base: "./",
  plugins: [vue(), ReactivityTransform()],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  server: {
    host: true,
    port: 4399,
    proxy: {
      "/api": {
        target: config.baseURL,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  build: {
    sourcemap: config.isTest,
    outDir: config.isTest ? "testdist" : "dist",
  },
  mode: config.isTest ? "development" : "production",
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `
          @use "@/styles/theme.scss" as *;
          `,
      },
    },
  },
});
